/*
 * @Author: weikang
 * @Description:
 * @Date: 2024-02-20 21:56:10
 * @LastEditTime: 2024-04-09 23:16:22
 * @FilePath: \env-manager-pc\src\views\system\config\page.ts
 */
import { AccountType } from '@/api/modules/types/user'

export function useRules() {
  return {
    'data.Name': {
      required: true, message: '请输入名称', trigger: 'blur',
    },
    'data.FullName': {
      required: true, message: '请输入全称', trigger: 'blur',
    },
  }
}

export interface OwnerOrgForm {
  parentOwnerOrgObjID: null | string
  ownerOrg: {
    Name: string
    Code: string
    FullName: string
  }
}
export interface DataForm {
  parentId: null | string
  data: {
    Name: string
    Code: string
    FullName: string
  }
}
export interface envOrgForm {
  parentEnvOrgObjID: null | string
  envOrg: {
    Name: string
    Code: string
    FullName: string
  }
}

export function CreateSubmitData(type: AccountType, data: DataForm): OwnerOrgForm | envOrgForm {
  return type === AccountType.OwnerOrg
    ? {
        parentOwnerOrgObjID: data.parentId,
        ownerOrg: data.data,
      }
    : {
        parentEnvOrgObjID: data.parentId,
        envOrg: data.data,
      }
}

export function useInitForm(): { formData: Ref<DataForm>, initForm: () => void } {
  const getData = (): DataForm => ({
    parentId: null,
    data: {
      Name: '',
      Code: '',
      FullName: '',
    },
  })
  const formData = ref<DataForm>(getData())

  const initForm = () => {
    formData.value = getData()
  }

  return { formData, initForm }
}
